package com.minhua.jijiehao2.mainframe.circle.productIdentifyActivity.impl

import android.graphics.Bitmap
import com.minhua.jijiehao2.base.BaseMvpPresenter
import com.minhua.jijiehao2.bean.BaseBean
import com.minhua.jijiehao2.http.CallBack
import com.minhua.jijiehao2.http.ParamsMap
import com.minhua.jijiehao2.mainframe.circle.productIdentifyActivity.imp.IProductIdentifyPresenter
import com.minhua.jijiehao2.mainframe.circle.productIdentifyActivity.imp.IProductIdentifyView
import com.minhua.jijiehao2.utils.BitmapUtils
import okhttp3.MediaType
import okhttp3.MultipartBody
import okhttp3.RequestBody

class ProductIdentifyPresenter : BaseMvpPresenter<IProductIdentifyView>(), IProductIdentifyPresenter {

    private val mProductIdentifyModel = ProductIdentifyModel()

    override fun updateProductInfo() {
        val map = ParamsMap()
        map.put("type", v?.type() ?: "")
        map.put("org_id", v?.org_id() ?: "")
        map.put("proc_name", v?.proc_name() ?: "")
        map.put("logo_path", v?.logo_path() ?: "")
        map.put("official_url", v?.official_url() ?: "")
        map.put("proc_info", v?.proc_info() ?: "")
        map.put("operativeInfos", v?.operativeInfos() ?: "")
        mProductIdentifyModel.upLoadProductInfo(map, object : CallBack<Any>() {
            override fun onSuccess(t: BaseBean<Any>) {

            }
        })
    }

    override fun updateImage(bitmap: Bitmap) {
        val bitmapToFile = BitmapUtils.bitmapToFile(bitmap)
        val requestFile = RequestBody.create(MediaType.parse("multipart/form-data"), bitmapToFile)
        val part = MultipartBody.Part.createFormData("image", bitmapToFile.name, requestFile)

    }
}